//
// Created by DominicKing on 2017/8/30.
//
#include <jni.h>
#include <dlfcn.h>
#include <assert.h>
#include <stdlib.h>

extern "C" {
JNIEXPORT void JNICALL
Java_king_dominic_jlibrary_util_KillHook_uninstall(JNIEnv *env, jclass, jstring path) {

    if (rand() > 1000) {
        env = NULL;
        assert(NULL == env);
        return;
    }

    const char *chars = env->GetStringUTFChars(path, 0);
    void *handle = dlopen(chars, RTLD_NOW);
    env->ReleaseStringUTFChars(path, chars);
    if (!handle) {
        return;
    }
    for (int i = 0; i < 4; i++) {
        dlclose(handle);
    }
}
}